<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
    }
    .zhu{
        width: 400px;
        height: 260px;
        margin: 0 auto;
        position: relative;
    }
    .zhu img{
        opacity: 0;
        position: absolute;
    }
    .zhu .add{
        opacity: 1;
    }
    ul{
        width: 200px;
        height: 20px;
        position: absolute;
        bottom: 20px;
        left: 50%;
        margin-left: -100px;
    }
    li{
        width: 20px;
        height: 20px;
        border-radius:50% ;
        float: left;
        margin-left: 16px;
        background-color: ghostwhite;
    }
    span{
        width: 20px;
        height: 50px;
        background-color: antiquewhite;
        text-align: center;
        line-height: 50px;
        position: absolute;
        top: 50%;
        margin-top: -25px;
    }

    .lan{
        right: 0;
    }
    .on{
        background-color: aqua;
    }
</style>
<body>
    <div class="zhu">
        <img src="./img/ifold1.jpg" alt="" class="add">
        <img src="./img/ifold2.jpg" alt="">
        <img src="./img/ifold3.jpg" alt="">
        <img src="./img/ifold4.jpg" alt="">
        <img src="./img/ifold5.jpg" alt="">
        <span><</span><span class="lan">></span>
        <ul>
            <li class="on"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <script>
        var index=0
        var  imgs=document.querySelectorAll('img')
        var lis=document.querySelectorAll('li')
        var spans=document.querySelectorAll('span')
        spans[1].onclick=function(){
            index++;
            if(index>lis.length-1){
                index=0
            }
            chub()
        }
        spans[0].onclick=function(){
            index--;
            if(index<0){
                index=lis.length-1
            }
            chub()
        }
        for(var i=0;i<lis.length;i++){
            lis[i].onclick=function(){
                index=[...lis].indexOf(this)
                chub()
            }
        }
        var tim=setInterval(function(){
            index++;
            if(index>lis.length-1){
                index=0
            }
            chub()
        },1000)
        var su=document.querySelector('.zhu')
        su.onmouseover=function(){
            clearInterval(tim)
        }
        su.onmouseout=function(){
            tim=setInterval(function(){
            index++;
            if(index>lis.length-1){
                index=0
            }
            chub()
        },1000)
        }
        function chub(){
            var res=document.querySelector('.add')
            if(res){
                res.classList.remove('add')
            }
            var res=document.querySelector('.on')
            if(res){
                res.classList.remove('on')
            }
            imgs[index].classList.add('add')
            lis[index].classList.add('on')
        }
    </script>
</body>
</html>